<template>
	<view class="contain">
		<view class="tables" style="margin-top:10px;">
			<u-row customStyle="margin-bottom: 10px">
				<u-col span="4" justify="center" align="center" textAlign="center">
					<view class="mid blod">课程章节</view>
				</u-col>
				<u-col span="4" justify="center" align="center" textAlign="center">
					<view class="mid blod">学习进度</view>
				</u-col>
				<u-col span="4" justify="center" align="center" textAlign="center">
					<view class="mid blod">开始时间</view>
				</u-col>
			</u-row>
		</view>
		<view class="tables" style="margin-top:10px;border-bottom:0px;" v-for="item in SubScribes.data">
			<u-row customStyle="margin-bottom: 10px">
				<u-col span="4" justify="center" align="center" textAlign="center">
					<view class="small">{{item.progress}}</view>
				</u-col>
				<u-col span="4" justify="center" align="center" textAlign="center">
					<view class="small">{{formatStatus(item.status)}}</view>
				</u-col>
				<u-col span="4" justify="center" align="center" textAlign="center">
					<view class="small" style="color:#00a100;">{{ formatTime(item.startTime) }}</view>
				</u-col>
			</u-row>
		</view>
	</view>
</template>

<script setup lang='ts'>
import { ref,reactive } from 'vue'
import { onLoad,onShow } from '@dcloudio/uni-app'
import {timetampToDate} from '@/common/date.js'
import { userStore } from '@/stores/userStore'
let store = userStore();	
let { hasLogin,userData } = userStore();

let SubScribes=reactive({data:[
	// {
	// 	"createtime":"2024-07-13",
	// 	"productname":"套餐A-老年人痴呆访谈 x1",
	// 	"orderprice":"93.8",
	// 	"paystatue":"未支付",
	// },
	// {
	// 	"createtime":"2024-07-13",
	// 	"productname":"套餐A-老年人痴呆访谈 x1",
	// 	"orderprice":"93.8",
	// 	"paystatue":"已支付",
	// }
]});


const formatTime=(timespame:string | number)=>{
	return timetampToDate(timespame);
}


/*
疏导状态
- 1：未开始
- 2：疏导中
- 3：已完成
*/
const formatStatus=(num:number)=>{
	if(num===2) return "疏导中";
	if(num===3) return "已完成";
	return "未开始";
}


/* 查询进度 */
const getCourseProgress=()=>{
	console.log("用户id",userData.userinfo.id);
	let paraData={
		id:userData.userinfo.id
	};
	uni.$tools.Reqeust('/api/getCourseProgress',paraData,'POST').then((res:any)=>{
			console.log('查询进度结果:',res);
			if (res.data.code == 200) {
				if(res.data.userinfo.coursestate!=null && res.data.userinfo.coursestate!=''){
					SubScribes.data=JSON.parse(res.data.userinfo.coursestate);
				}
				
			}else{
				uni.$tools.Toast(res.data.msg);
			}
	})	
}

onLoad(()=>{
	getCourseProgress();
});

onShow(()=>{
	if(userData.userinfo===null || hasLogin===false){
		uni.$tools.Toast("会话失效请重新登录");
		setTimeout(()=>{
			uni.$tools.GoUrl('/pages/login/login',0);
		},1000);
		return;
	}
})
</script>

<style lang='scss' scoped>
	@import "studyprogress.scss";
</style>